﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.UI;

using ProjectBase.Core;

namespace $safeprojectname$
{
    public class DefinitionListItem : ContentControl<ICoreModel, IVisualControl, DefinitionListItem>
    {
        #region members
        DT _dt;
        Label _label;
        #endregion members

        #region constructor
        public DefinitionListItem(string label = null, bool doLocalize = true, string cssClassName = null)
            : base(cssClassName)
        {
            _label = new Label(label, doLocalize);
            _dt = new DT
            {
                _label,
            };

            base.Add(_dt);
        }
        #endregion constructor

        #region Add -> wrap with DD
        public override void Add(IVisualControl control)
        {
            if (control.IsNull())
            {
                return;
            }
            Controls.Add(control is DD ? control : new DD { control });
            if (!Label.HasText)
            {
                Label.SetText(control.ID); // set the label with localized Text
            }
        }
        #endregion Add -> to DIV

        #region Set
        public virtual DefinitionListItem SetLabel(string text, bool doLocalize = true)
        {
            Label.SetText(text, doLocalize);
            return this;
        }

        public virtual DefinitionListItem HideLabel(bool hide)
        {
            if (hide)
            {
                DT.Controls.Remove(Label);
            }
            else
            {
                DT.Controls.Remove(Label);
                DT.Controls.AddAt(0, Label);
            }
            return this;
        }
        #endregion Set

        #region properties
        protected virtual DT DT
        {
            get { return _dt; }
            set { _dt = value; }
        }

        protected virtual Label Label
        {
            get { return _label; }
            set { _label = value; }
        }
        #endregion properties
    }
}